/**
 * 
 */
package txt2bib.util;

import java.util.HashMap;
import java.util.LinkedList;

import txt2bib.GrammarCup;
import txt2bib.GrammarElsevierCup;
import txt2bib.GrammarError;
import txt2bib.GrammarIEEECup;
import txt2bib.GrammarSpringerCup;

/**
 * @author v
 *
 */
public class ErrorHelper {
	private static ErrorHelper instance = null;
	
	HashMap<Grammars, LinkedList<GrammarError>> errors = null;
	HashMap<Grammars, String> lastProd = null;
	
	private ErrorHelper() {
		errors = new HashMap<Grammars, LinkedList<GrammarError>>();
	}
	
	public synchronized static ErrorHelper getInstance() {
		return (instance == null) ? (instance = new ErrorHelper()) : instance; 
	}
	
	public LinkedList<GrammarError> initialize(Class<?> _class) {
		if (_class.equals(GrammarCup.class)) {
			errors.put(Grammars.ACM, new LinkedList<GrammarError>()); 
			return errors.get(Grammars.ACM);
		} else if (_class.equals(GrammarSpringerCup.class)) {
			errors.put(Grammars.Springer, new LinkedList<GrammarError>());
			return errors.get(Grammars.Springer);
		} else if (_class.equals(GrammarElsevierCup.class)) {
			errors.put(Grammars.Elsevier, new LinkedList<GrammarError>()); 
			return errors.get(Grammars.Elsevier);
		} else if (_class.equals(GrammarIEEECup.class)) { 
			errors.put(Grammars.IEEE, new LinkedList<GrammarError>()); 
			return errors.get(Grammars.IEEE);
		} 
		return null;
	}
	
	public void addError(Class<?> _class, GrammarError error) {
		if (_class.equals(GrammarCup.class)) {
			errors.get(Grammars.ACM).add(error);
			
		} else if (_class.equals(GrammarSpringerCup.class)) {
			errors.get(Grammars.Springer).add(error);
			
		} else if (_class.equals(GrammarElsevierCup.class)) {
			errors.get(Grammars.Elsevier).add(error);
			
		} else if (_class.equals(GrammarIEEECup.class)) {
			errors.get(Grammars.IEEE).add(error);
		}
	}
	
	public void addProd(Class<?> _class, String string) {
		if (_class.equals(GrammarCup.class)) {
			lastProd.put(Grammars.ACM, string);
			
		} else if (_class.equals(GrammarSpringerCup.class)) {
			lastProd.put(Grammars.Springer,string);
			
		} else if (_class.equals(GrammarElsevierCup.class)) {
			lastProd.put(Grammars.Elsevier,string);
			
		} else if (_class.equals(GrammarIEEECup.class)) {
			lastProd.put(Grammars.IEEE,string);
		}
	}
	
	
	public String getProd(Grammars gr) {
		return lastProd.get(gr);
	}
	
	
	public LinkedList<GrammarError> getErrors(Grammars gr) {
		return errors.get(gr);	
	}
}
